package mvp.com.mvpdemo.model;

import mvp.com.mvpdemo.model.bean.User;
import mvp.com.mvpdemo.view.IUserLoginView;

/**
 * Created by YoungerChen on 2016/9/13.
 */
public class UserBiz implements IUserBiz {

    @Override
    public void login(String username, String password, IUserLoginView.OnLoginListener loginListener) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        login(user, loginListener);
    }

    @Override
    public void login(final User user, final IUserLoginView.OnLoginListener loginListener) {

        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                // 模拟登陆成功
                if ("nihao".equals(user.getUsername()) && "123".equals(user.getPassword())) {
                    User u = new User();
                    u.setUsername(user.getUsername());
                    u.setPassword(user.getPassword());
                    loginListener.loginSuccess(user);

                } else {
                    loginListener.loginFailed();
                }
            }
        }.start();
    }
}
